<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<title>信息管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
    <script type="text/javascript" src="${ctx}/js/easyui/extendvalidate.js"></script>
     <script type="text/javascript" src="${ctx}/js/credit/rules.js"></script>
	<style type="text/css">
	.rules_font { font-size: 12px; }
	</style>
	<script type="text/javascript">
		function doSubmit(url,datas,tabId){
			var rows = $("#creditCodeList").datagrid("getRows");
			var x =0;
			var creditCode ="";
			var flag =true;
			for(var i=0; i<rows.length; i++){
				if(creditCode.indexOf(rows[i].creditCode) >= 0 ){
					flag = false;
					break;
				}
				x += parseInt(rows[i].creditWeight);
				creditCode+=rows[i].creditCode;
			}
			if(flag){
				if(x>100){
					alert("权重累加已超过100%");
					editTr(tabId);
				}else{
					if(url==''){
						url = "${ctx}/credit/saveCode.action";
					}
					$.ajax({
						type: "post",
						data:datas,
						dataType: "json",
						url: url,
						success: function(data, textStatus){
							if("T"==data.flag || "F"==data.flag){
								$.messager.alert('结果', data.msg, 'info',function(){
									 $('#'+tabId).datagrid('reload');
								});	
							}
						}
					});
				}
			}else{
				alert("信用标识重复!");
				editTr(tabId);
			}
		}
	</script>
</head>
<body>

    <table id="creditCodeList"></table>
	<input type="hidden" name="isAdd" id="isAdd" value="true" >
</body>
 <script type="text/javascript">
   $(function(){
	    $('#creditCodeList').datagrid({
	        title: '信用指标列表',  
	        nowrap: false,
			striped: true,
			collapsible:false,				
			fitColumns: true,
			singleSelect:true,
			rownumbers:true,
			loadMsg: "正在加载数据...",
			idField:'creditId',
	        url: '${ctx }/credit/list!data.action',
			columns:[[  
            {field:'creditCode',title:'标识',width:100,align:'center',editor:'text'},
			{field:'creditName',title:'名称',width:150,align:'center',editor:'text'},
			{field:'creditWeight',title:'权重(%)',width:100,align:'right',editor:{options:{required:true},type:'numberbox'}},
			{field:'creditRemark',title:'描述',width:200,editor:'text'}
			]],
			toolbar:[{
				text:'保存',
				iconCls:'icon-save',
				handler:function(){
					saveTransactionTime('creditCodeList','normal');
				}
			},'-',{
				text:'添加行',
				iconCls:'icon-add',
				handler:function(){
						var row = $('#creditCodeList').datagrid('getSelected');
						var rowIndex = $('#creditCodeList').datagrid('getRowIndex',row);
						if(rowIndex !=-1){
							saveTransactionTime('creditCodeList','normal');
						}
						append('creditCodeList');
				}
			},'-',{
				text:'删除行',
				iconCls:'icon-remove',
				handler:function(){
					removeInfo('creditCodeList');
				}
			}],
			onDblClickRow:function(rowIndex, rowData){
				$("#isAdd").val("false");
				onClickRow('creditCodeList',rowIndex);
			}
		});
   });
   function removeInfo(tabId){
		var row = $('#'+tabId).datagrid('getSelected');
		if (row) {
	      if(!row.creditId){
	    	  var rowIndex = $('#'+tabId).datagrid('getRowIndex', row);
	    	  $('#'+tabId).datagrid('deleteRow', rowIndex);  
			  $('#'+tabId).datagrid('reload');//删除后重新加载下
			  editIndex = undefined;
		  }else{
			$.ajax({
				type: "post",
				url: "${ctx }/credit/del.action?id="+row.creditId,
				dataType: "json",
				success: function(data){
					var result = data;
					if(result.flag=='T'){
						$.messager.alert('结果', '操作成功', 'info');	
						 var rowIndex = $('#'+tabId).datagrid('getRowIndex', row);
						   $('#'+tabId).datagrid('deleteRow', rowIndex);  
						   $('#'+tabId).datagrid('reload');//删除后重新加载下
						   editIndex = undefined;
					}else{
						$.messager.alert('结果', result.msg, 'info');	
					}
				}
			});
		  }
	    }
	}
</script>
</html>